package com.igeek.shop.web.gouwuche;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.igeek.shop.service.gouwuche.LinkageService;



public class LinkageServlet extends HttpServlet{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String state= req.getParameter("state");
		if(state.equals("init")){
			initProvince(req,resp);
		}else if(state.equals("city")){
			initCity(req,resp);
		}else if(state.equals("area")){
			initArea(req,resp);
		}else if(state.equals("areatwo")){
			areatwo(req,resp);
		}
	}

	private void areatwo(HttpServletRequest req, HttpServletResponse resp) {
		// TODO Auto-generated method stub
		String aid = req.getParameter("aid");
		req.removeAttribute("aid");
		req.getSession().setAttribute("aid", aid);
		//System.out.println("我是县级"+aid);
	}


	private void initArea(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		// TODO Auto-generated method stub
		String cid = req.getParameter("cid");
		Object[] params = {cid};
		req.removeAttribute("cid");
		req.getSession().setAttribute("cid", cid);
		//System.out.println("我是市级"+cid);
		LinkageService.getJson(params, resp);
	}

	private void initCity(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		// TODO Auto-generated method stub
		String pid = req.getParameter("pid");
		Object[] params = {pid};
		req.removeAttribute("pid");
		req.getSession().setAttribute("pid", pid);
		//System.out.println("我是省级"+pid);
		LinkageService.getJson(params, resp);
	}

	private void initProvince(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		// TODO Auto-generated method stub
		Object [] params = {0};
		LinkageService.getJson(params,resp);
	}

	
	
}
